package tool

import play.api.data._
import play.api.data.Forms._
import play.api.data.JodaForms.jodaDate

/**
 * Created by yz on 2018/7/17
 */

import Pojo._

class FormTool {

  case class AccountData(account: String, password: String)

  val accountForm = Form(
    mapping(
      "account" -> text,
      "password" -> text
    )(AccountData.apply)(AccountData.unapply)
  )

  case class userNameData(name: String)

  val userNameForm = Form(
    mapping(
      "name" -> text
    )(userNameData.apply)(userNameData.unapply)
  )

  val configNameForm = Form(
    mapping(
      "configName" -> text
    )(ConfigNameData.apply)(ConfigNameData.unapply)
  )

  val idOpForm = Form(
    mapping(
      "id" -> optional(number)
    )(IdOpData.apply)(IdOpData.unapply)
  )


  val saveConfigForm = Form(
    mapping(
      "missionName" -> text,
      "configName" -> text
    )(ConfigFormData.apply)(ConfigFormData.unapply)
  )

  val userForm = Form(
    mapping(
      "name" -> text,
      "password" -> text
    )(UserData.apply)(UserData.unapply)
  )

  val unitForm = Form(
    mapping(
      "unit" -> text
    )(UnitData.apply)(UnitData.unapply)
  )

  val loginUserForm = Form(
    mapping(
      "name" -> text,
      "password" -> text
    )(LoginUserData.apply)(LoginUserData.unapply)
  )

  case class IdData(id: Int)

  val idForm = Form(
    mapping(
      "id" -> number
    )(IdData.apply)(IdData.unapply)
  )

  val sampleIdForm = Form(
    mapping(
      "id" -> text
    )(SampleIdData.apply)(SampleIdData.unapply)
  )

  case class ChangePasswordData(password: String, newPassword: String)

  val changePasswordForm = Form(
    mapping(
      "password" -> text,
      "newPassword" -> text
    )(ChangePasswordData.apply)(ChangePasswordData.unapply)
  )

  case class MissionNameData(missionName: String)

  val missionNameForm = Form(
    mapping(
      "missionName" -> text
    )(MissionNameData.apply)(MissionNameData.unapply)
  )

  case class AdjustMissionData(mission: String)

  val adjustMissionForm = Form(
    mapping(
      "mission" -> text,
    )(AdjustMissionData.apply)(AdjustMissionData.unapply)
  )

  case class MissionIdOptionData(missionId: Option[Int])

  val missionIdOptionForm = Form(
    mapping(
      "missionId" -> optional(number)
    )(MissionIdOptionData.apply)(MissionIdOptionData.unapply)
  )

  case class ArgsData(missionId: Int, compoundName: String)

  val argsForm = Form(
    mapping(
      "missionId" -> number,
      "compoundName" -> text,
    )(ArgsData.apply)(ArgsData.unapply)
  )

  val strForm = Form(
    mapping(
      "strSiteNames" -> seq(text),
      "strSiteDatas" -> seq(text)
    )(StrData.apply)(StrData.unapply)
  )

  val snpForm = Form(
    mapping(
      "snpSiteNames" -> seq(text),
      "snpSiteDatas" -> seq(text)
    )(SnpData.apply)(SnpData.unapply)
  )

  case class ParamAdjustData(missionName: String, missionId: Int, compoundName: String, flMin: String, flMax: String, step: String, nups: String,
                             ndowns: String, snr: String, iteration: String, bLine: String, rtlw: String, rtrw: String,
                             rt: String, peakLocation: String)

  val paramAdjustForm = Form(
    mapping(
      "missionName" -> text,
      "missionId" -> number,
      "compoundName" -> text,
      "flMin" -> text,
      "flMax" -> text,
      "step" -> text,
      "nups" -> text,
      "ndowns" -> text,
      "snr" -> text,
      "iteration" -> text,
      "bLine" -> text,
      "rtlw" -> text,
      "rtrw" -> text,
      "rt" -> text,
      "peakLocation" -> text
    )(ParamAdjustData.apply)(ParamAdjustData.unapply)
  )

  case class UnitConversionData(unit: String, toUnit: String, fromC: Int)

  val unitConversionForm = Form(
    mapping(
      "unit" -> text,
      "toUnit" -> text,
      "fromC" -> number
    )(UnitConversionData.apply)(UnitConversionData.unapply)
  )

  case class FileNameData(fileName: String)

  val fileNameForm = Form(
    mapping(
      "fileName" -> text
    )(FileNameData.apply)(FileNameData.unapply)
  )

  case class FileNamesData(fileNames: Seq[String])

  val fileNamesForm = Form(
    mapping(
      "fileNames" -> seq(text)
    )(FileNamesData.apply)(FileNamesData.unapply)
  )

}

object FormTool {

  val missionNameCheckForm = Form(
    mapping(
      "missionName" -> text,
      "kind" -> text,
    )(MissionNameCheckData.apply)(MissionNameCheckData.unapply)
  )

  val searchForm = Form(
    mapping(
      "missionName" -> optional(text),
      "missionIntro" -> optional(text),
      "startDate" -> optional(jodaDate),
      "endDate" -> optional(jodaDate)
    )(SearchData.apply)(SearchData.unapply)
  )

  val sampleSearchForm = Form(
    mapping(
      "id" -> text,
      "indexId" -> text,
      "sampleIntro" -> text,
      "gender" -> text,
      "kind" -> text,
      "comment" -> text,
      "updateMission" -> text,
      "startDate" -> optional(jodaDate),
      "endDate" -> optional(jodaDate)
    )(SampleSearchData.apply)(SampleSearchData.unapply)
  )

  val missionForm = Form(
    mapping(
      "missionName" -> text,
      "lane" -> text,
      "id" -> text,
      "gender" -> text,
      "kind" -> text
    )(MissionData.apply)(MissionData.unapply)
  )

  val sampleIdForm = Form(
    mapping(
      "id" -> text
    )(SampleIdData.apply)(SampleIdData.unapply)
  )

  val sampleSummaryForm = Form(
    mapping(
      "id" -> text,
      "panel" -> text
    )(SampleSummaryData.apply)(SampleSummaryData.unapply)
  )

  val onlyPanelForm = Form(
    mapping(
      "onlyPanel" -> default(boolean,false)
    )(OnlyPanelData.apply)(OnlyPanelData.unapply)
  )

  val kindForm = Form(
    mapping(
      "kind" -> optional(text)
    )(KindData.apply)(KindData.unapply)
  )

  val missionNameForm = Form(
    mapping(
      "missionName" -> text
    )(MissionNameData.apply)(MissionNameData.unapply)
  )

  val idForm = Form(
    mapping(
      "id" -> text
    )(IdData.apply)(IdData.unapply)
  )

  val idsForm = Form(
    mapping(
      "ids" -> list(text)
    )(IdsData.apply)(IdsData.unapply)
  )

  val passwordForm = Form(
    mapping(
      "password" -> text
    )(PasswordData.apply)(PasswordData.unapply)
  )

  val stepForm = Form(
    mapping(
      "missionName" -> text,
      "stepNum" -> number,
      "id" -> text,
      "kitName" -> text,
      "containerName" -> optional(list(text))
    )(StepData.apply)(StepData.unapply)
  )

  val batchMissionForm = Form(
    mapping(
      "missionIntro" -> text,
      "dataType" -> text,
      "splitDir" -> text,
      "serverGzFile" -> text,
      "isCover" -> optional(boolean)
    )(BatchMissionData.apply)(BatchMissionData.unapply)
  )

  val serverDirForm = Form(
    mapping(
      "splitDir" -> text
    )(ServerDirData.apply)(ServerDirData.unapply)
  )

  val adminSetForm = Form(
    mapping(
      "gzPath" -> text,
    )(AdminSetData.apply)(AdminSetData.unapply)
  )

  val nodeForm = Form(
    mapping(
      "id" -> text,
    )(NodeData.apply)(NodeData.unapply)
  )

  val missionIdForm = Form(
    mapping(
      "missionId" -> number
    )(MissionIdData.apply)(MissionIdData.unapply)
  )

  val siteNamesForm = Form(
    mapping(
      "siteNames" -> seq(text)
    )(SiteNamesData.apply)(SiteNamesData.unapply)
  )

  val columnNamesForm = Form(
    mapping(
      "columnNames" -> seq(text)
    )(ColumnNamesData.apply)(ColumnNamesData.unapply)
  )

  val sexForm = Form(
    mapping(
      "sex" -> text
    )(SexData.apply)(SexData.unapply)
  )

  val compareMissionForm = Form(
    mapping(
      "userId" -> number,
      "missionName" -> text,
      "sample1" -> text,
      "sample2" -> text
    )(CompareMissionData.apply)(CompareMissionData.unapply)
  )

  val kitNameForm = Form(
    mapping(
      "kitName" -> text
    )(KitNameData.apply)(KitNameData.unapply)
  )

  val exportDatForm = Form(
    mapping(
      "isSplit" -> boolean,
      "hasGroup" -> boolean,
      "sampleNum" -> text,
    )(ExportDatData.apply)(ExportDatData.unapply)
  )

  val sampleIdsForm = Form(
    mapping(
      "ids" -> seq(text)
    )(SampleIdsData.apply)(SampleIdsData.unapply)
  )

  val pageForm = Form(
    mapping(
      "limit" -> number,
      "offset" -> number,
      "order" -> text,
      "search" -> optional(text),
      "sort" -> optional(text),
      "gender" -> optional(list(text)),
      "kind" -> optional(list(text)),
      "panel" ->optional(list(text)),
      "id" -> optional(text),
      "indexId" -> optional(text),
      "sampleIntro" -> optional(text),
      "comment" -> optional(text),
      "updateMission" -> optional(list(text)),
      "startTime" -> optional(jodaDate),
      "endTime" -> optional(jodaDate),
      "containerName" -> optional(list(text)),
      "singleSource" -> optional(list(text)),
      "autosomalLociTyped" -> optional(list(text)),
      "yLociTyped" -> optional(list(text)),
      "xLociTyped" -> optional(list(text)),
      "isnpLociTyped" -> optional(list(text)),
      "interlocusBalance" -> optional(list(text))
    )(PageData.apply)(PageData.unapply)
  )

  val pageQueryForm = Form(
    mapping(
      "gender" -> optional(list(text)),
      "kind" -> optional(list(text)),
      "panel" ->optional(list(text)),
      "id" -> optional(text),
      "indexId" -> optional(text),
      "sampleIntro" -> optional(text),
      "comment" -> optional(text),
      "updateMission" -> optional(list(text)),
      "startTime" -> optional(jodaDate),
      "endTime" -> optional(jodaDate),
      "containerName" -> optional(list(text)),
      "singleSource" -> optional(list(text)),
      "autosomalLociTyped" -> optional(list(text)),
      "yLociTyped" -> optional(list(text)),
      "xLociTyped" -> optional(list(text)),
      "isnpLociTyped" -> optional(list(text)),
      "interlocusBalance" -> optional(list(text))
    )(PageQueryData.apply)(PageQueryData.unapply)
  )



}
